const newLocal =require('../../data/play3.2');
const {episodes,new_ep,evaluate,rating,season_title,cover:cartoonImg,seasons,season_id,section,series}=newLocal.result;
rating.count=(rating.count/10000).toFixed(1);
const danmuList= require('../../data/danmu');
const db=wx.cloud.database();
const cartoonsCollection=db.collection("cartoons");
let pinglun=require('../../data/pinglun');

// pages/play/play.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentId:0,
    danmu:true,
    danmuList,
    episodes,
    new_ep,
    evaluate,
    rating,
    season_title,
    cartoonImg,
    seasons,
    section,
    views:(seasons[0].stat.views/10000).toFixed(1),
    favorites:(seasons[0].stat.favorites/10000).toFixed(1),
    series,
    isChase:'追番',
    videoId:episodes[0].aid,
    videoUrl:episodes[0].link,
    shareTitle:episodes[0].share_copy,
    shareImg:episodes[0].cover,
    seasonId:season_id,
    pinglun
  },
  danmuon(){
    if(this.data.danmu){
      this.setData({
        danmuList:[],
        danmu:false
      })
    }
    else{
      this.setData({
        danmuList:danmuList,
        danmu:true
      })
    }
  },
  changeCurrent(e){
    console.log(e);
    let currentId=e.currentTarget.dataset.current;
    this.setData({
      currentId
    })
    console.log(this.data.currentId !=0 )
  },
  changeVideo(e){
    let videoId=e.currentTarget.dataset.videoid;
    let videoUrl=e.currentTarget.dataset.videourl;
    let shareTitle=e.currentTarget.dataset.sharetitle;
    let shareImg=e.currentTarget.dataset.shareimg;
    this.setData({
      videoId,
      videoUrl,
      shareTitle,
      shareImg
    })
    // console.log(this.data.videoId);
  },
  changeSeason(e){
    let seasonId=e.currentTarget.dataset.seasonid;
    cartoonsCollection
    .where({
      season_id:seasonId
    })
    .get()
    .then(res=>{
      let {episodes,new_ep,evaluate,rating,season_title,cover:cartoonImg,seasons,season_id,section,series}=res.data[0];
      if(!section){section=[]};
      rating.count=(rating.count/10000).toFixed(1);
      this.setData({
        episodes,
        new_ep,
        evaluate,
        rating,
        season_title,
        cartoonImg,
        seasons,
        section,
        views:(seasons[0].stat.views/10000).toFixed(1),
        favorites:(seasons[0].stat.favorites/10000).toFixed(1),
        series,
        isChase:'追番',
        videoId:episodes[0].aid,
        videoUrl:episodes[0].link,
        seasonId:season_id
      })
    })
  },
  changeChase(){
    if(this.data.isChase=='追番'){
      this.setData({
        isChase:'已追番'
      })
    }
    else{
      this.setData({
        isChase:'追番'
      })
    }
  },
  share(){

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options){
    // console.log(options);
    const {videoid,season_id}=options
    if(videoid){
      this.setData(
        {
          videoId:videoid
        }
      )
    }
    this.setData({
      
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
      return{
        title:this.data.shareTitle,
        imageUrl:this.data.shareImg,
        path:"/pages/cartoon/cartoon?videoid="+this.data.videoId
        }
  }
})